from api.handler.ce.AbstractBatchCE import AbstractBatchCE
from api.model.BatchOutputPipe import BatchOutputPipe
from api.model.FdInputPipe import FdInputPipe
from munch import Munch
import json
# from config.annotation import Value

class DangerLevelHandler(AbstractBatchCE):
    """ 本科在籍分学院 """
    def do_compute(self, output_stream: BatchOutputPipe, source_fds: FdInputPipe, params: dict):
        jbxx_fd = source_fds.get_fd('VDJ_JW_XSJBSJZLB')
        jbxx_sql = """
        SELECT XH, XM, XB, CSRQ, JG, MZM, GJDQ, ZZMM
FROM VDJ_JW_XSJBSJZLB
WHERE XJZT = '是'
        """
        jbxx_results = jbxx_fd.query(jbxx_sql)

        xjxx_fd = source_fds.get_fd('VDJ_JW_XJJBSJZLB')
        xjxx_sql = """
        SELECT XH, SZNJ, YXSH, ZYM, XZ
FROM VDJ_JW_XJJBSJZLB
WHERE XSDQZT = '是'
        """
        xjxx_results = xjxx_fd.query(xjxx_sql)
        for jbxx in jbxx_results:
            data = Munch()
            data.number = jbxx.XH
            data.name = jbxx.XM
            data.sex = jbxx.XB
            data.native = jbxx.get('JG', '不详')
            data.nation = jbxx.get('MZM', '不详')
            data.contry = jbxx.get('GJDQ', '不详')
            data.politics = jbxx.get('ZZMM', '不详')
            for xjxx in xjxx_results:
                if str(jbxx.XH) == str(xjxx.XH):
                    data.dept = xjxx.get('YXSH', '不详')
                    data.grade = xjxx.get('SZNJ', '不详')
                    data.major = xjxx.get('ZYM', '不详')
                    data.school_length = xjxx.XZ
                    break

            output_stream.output_for_upsert(data)



